<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script>
			function checkData(){
				var data = document.getElementById("data");
				if (data.value=="") {
					alert("不能为空");
					return false;
				} else{
					return true;
				}
			}
		</script>
	</head>
	<body>
		<form action="https://www.baidu.com/s" method="get" onsubmit="return checkData()">
			<input type="text" name="wd" id="data" />
			<input type="submit" value="百度一下"/>
		</form>
	</body>
</html>
